package com.gp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gp.dao.MaintainShopDao;
import com.gp.entity.MaintainShop;
import com.gp.service.MaintainShopService;
import com.gp.util.CommonResult;
import com.gp.vo.MaintainShopVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName MaintainShopServiceImpl
 * @Description //TODO
 * @Author luzzh
 * @Date 2022/3/8 20:38
 */
@Service
public class MaintainShopServiceImpl implements MaintainShopService {
    @Autowired
    private MaintainShopDao maintainShopDao;
    //查询id
    @Override
    public CommonResult selectById(Integer id) {
        MaintainShop maintainShop = maintainShopDao.selectById(id);
        return new CommonResult(200,"查询成功",maintainShop);
    }

    //查询所有
    @Override
    public CommonResult findAllMaintain() {
        List<MaintainShop> maintainShops = maintainShopDao.selectList(null);
        return new CommonResult(200,"查询成功",maintainShops);
    }

    @Override
    public CommonResult addMaintain(MaintainShop maintainShop) {
        return new CommonResult(200,"添加成功",maintainShopDao.insert(maintainShop));
    }

    @Override
    public CommonResult updateMaintain(MaintainShop maintainShop) {
        return new CommonResult(200,"修改成功",maintainShopDao.updateById(maintainShop));
    }

    @Override
    public CommonResult deleteMaintain(Integer id) {
        return new CommonResult(200,"删除成功",maintainShopDao.deleteById(id));
    }

    @Override
    public CommonResult selectByPage(Integer currentPage, Integer pageSize, MaintainShopVo shopVo) {
            Page<MaintainShop> page=new Page<>(currentPage,pageSize);
            QueryWrapper<MaintainShop> shopQueryWrapper=new QueryWrapper<>();
            if (StringUtils.isNotEmpty(shopVo.getName())){
                shopQueryWrapper.like("name",shopVo.getName());
            }
            Page<MaintainShop> shopPage=maintainShopDao.selectPage(page,shopQueryWrapper);
            return new CommonResult(200,"查询成功",shopPage);
    }
}

